﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySql.Data.MySqlClient;
using System.Data;

namespace emulib
{
    class MySQLHandler : IMmoDatabase
    {
        MySqlConnection mysqlConnection;
        public Boolean Connect(ServerInfo sinfo)
        {
            mysqlConnection = new MySqlConnection(
            String.Format("server={0};user id={1};password={2};database={3};",
            sinfo.dbInfo.sqlhost, sinfo.dbInfo.sqluser, sinfo.dbInfo.sqlpass, sinfo.dbInfo.sqldb));
            try
            {
                mysqlConnection.Open();
            }
            catch (Exception e)
            {
                Console.WriteLine("Connection error: " + e.Message);
                return false;
            }
            return true;
        }
        public void Disconnect()
        {
            mysqlConnection.Close();
        }
        public IDataRecord Select(String what, String from, String where = null, String orderBy = null, Boolean direction = false, Int32 limitStart = -1, Int32 limitMax = -1)
        {
            return new MySqlCommand().ExecuteReader();
        }
    }
}
